package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	str := "hello郑"       // ascii的字符
	fmt.Println(len(str)) // 8
	// ascii的字符 长度问题
	/*for i:=0;i<len(str);i++ {
		fmt.Println(str[i])
	}*/
	// 字符串遍历问题
	r := []rune(str)
	for i := 0; i < len(r); i++ {
		fmt.Printf("字符=%c \n", r[i])
	}

	fmt.Println("==字符串转整数===")
	n, err := strconv.Atoi("hello")
	if err != nil {
		fmt.Println("转换失败", err)
	} else {
		fmt.Println("转换成功", n)
	}
	fmt.Println("==整数转字符串===")
	str2 := strconv.Itoa(123)
	fmt.Printf("str2=%v, %T", str2, str2)

	fmt.Println("==字符串转整数===")
	byte1 := []byte("hello go")
	fmt.Printf("byte=%v, %T \n", byte1, byte1)

	str3 := string([]byte{97, 98, 99})
	fmt.Printf("str3=%v, %T \n", str3, str3)

	// 10进制转换为 2，8，16
	str4 := strconv.FormatInt(123, 2)
	fmt.Println(str4)
	str5 := strconv.FormatInt(123, 8)
	fmt.Println(str5)
	str6 := strconv.FormatInt(123, 16)
	fmt.Println(str6)

	fmt.Println(strings.Contains("1234", "12"))
	fmt.Println(strings.Count("1234", "12"))

	fmt.Println("abc" == "Abc")
	fmt.Println(strings.EqualFold("abc", "Abc"))

	fmt.Println(strings.Index("abcb", "b"))

	fmt.Println(strings.Replace("abcddd", "d", "e", -1))

	fmt.Println(strings.TrimSpace(" abc "))

	fmt.Println(strings.Trim(": a: bc:", ": "))

	fmt.Println(strings.HasPrefix("!aa", "!"))
	fmt.Println(strings.HasSuffix("aa!", "!"))

	// string 修改
	str7 := "a,b,c"
	arr1 := []byte(str7)
	arr1[0] = 'z'
	str7 = string(arr1)
	fmt.Println(str7)
}
